package demo8;


import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Spring容器的配置类
 *
 * 被@Configurable注解的类，就是配置类
 */

@Configuration
@ComponentScan("demo8")//指明容器要扫描哪个包
public class Config {

    @Bean
    public Student initStudent(){
        return new Student();
    }

    @Bean
    public DruidDataSource initDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setMaxActive(10);//池中最大连接数
        dataSource.setInitialSize(5);//初始化时创建的连接数
        return dataSource;
    }
}
